package edu.gyc.hishiro.service.impl;

import edu.gyc.hishiro.dao.SysRoleDao;
import edu.gyc.hishiro.model.SysPermission;
import edu.gyc.hishiro.model.SysRole;
import edu.gyc.hishiro.model.UserInfo;
import edu.gyc.hishiro.dao.UserInfoDao;
import edu.gyc.hishiro.service.UserInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ls
 * @since 2020-06-24
 */
@Service
public class UserInfoServiceImpl extends ServiceImpl<UserInfoDao, UserInfo> implements UserInfoService {



    @Autowired
    UserInfoDao userInfoDao;
    @Override
    public UserInfo findByUsername(String name) {
        UserInfo userInfo=lambdaQuery().eq(UserInfo::getUsername,name).one();
        if (userInfo != null) {
            //刚注册的用户没有权限，查询用户为空，要转存一下，不能直接赋值给userinfo
         UserInfo   t = userInfoDao.getUserAndRolesAndPermissions(userInfo.getUid());
            if (t != null) {
                userInfo.setRoles(t.getRoles());
                userInfo.setPermissions(t.getPermissions());
            }

        }
        return userInfo;
    }
}
